<template>
  <router-view/>
</template>
<script>
  import { ref, onMounted, watch } from 'vue'
  import { useStore } from 'vuex'
  import { initWebsocket, closeWebsocket } from "./utils/websocket";

  export default{
    name: 'App',
    setup() {
      const store = useStore()
      const islogin = ref(store.getters.islogin)
      onMounted(() => {
        if (islogin.value) {
          initWebsocket(store)
        } else {
          closeWebsocket()
        }
      })
      watch(() => {
        return store.getters.islogin
      }, (newValue) => {
        if (newValue) {
          initWebsocket(store)
        } else {
          closeWebsocket()
        }
      })
    }
  }
</script>
